package com.lww.integral.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lww.integral.mapper.TabCommodityMapper;
import com.lww.integral.service.TabCommodityService;
import com.lww.springcloudapi.entity.TabCommodity;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lww.springcloudapi.entity.TabGradeLog;
import com.lww.springcloudapi.pojo.TabHallUsermessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 积分商城 服务实现类
 * </p>
 *
 * @author SHEN
 * @since 2021-03-11
 */
@Service
public class TabCommodityServiceImpl extends ServiceImpl<TabCommodityMapper, TabCommodity> implements TabCommodityService {

    @Autowired
    TabCommodityMapper tabCommodityMapper;


    @Override
    public Page<TabCommodity> findQueryByCommodity(String cname, Integer money, Integer pageNo, Integer pageSize) {
        Page<TabCommodity> page = new Page(pageNo, pageSize);
        QueryWrapper<TabCommodity> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(cname != null && cname != "", "cName", cname)
                .gt(money != null && money != 0, "money", money)
                .orderBy(money != null && money != 0, true, "money");
        page = tabCommodityMapper.selectPage(page, queryWrapper);
        return page;
    }


    @Override
    public boolean findInsertCommodity(TabCommodity tabCommodity) {
        int insert = tabCommodityMapper.insert(tabCommodity);
        return insert > 0;
    }

    @Override
    public boolean findUpdateCommodity(TabCommodity tabCommodity) {
        return tabCommodityMapper.updateById(tabCommodity) > 0;
    }

    @Override
    public boolean findDelCommodity(Integer id) {
        return tabCommodityMapper.deleteById(id) > 0;
    }


}
